package priv.stones.common;

import java.util.Observable;
import java.util.Observer;

/**
 * @Author: Stones
 * @Description:观察者设计模式
 * @Date: 2017/9/26 13:36
 */

class House extends Observable {

    private int price;

    public void setPrice(int price) {
        if (this.price < price) {
            super.setChanged();
            super.notifyObservers(price);
        }
        this.price = price;
    }
}

class People implements Observer {

    @Override
    public void update(Observable o, Object arg) {
        System.out.println(arg.getClass());
        System.out.println("房价上涨到：" + arg);
    }

}


public class Observer1 {

    public static void main(String[] args) {
        House house = new House();
        house.setPrice(10000);
        house.addObserver(new People());
        house.addObserver(new People());
        house.addObserver(new People());
        house.setPrice(3000);
        house.setPrice(30000);
    }

}
